package com.example.exerciseextract2.base;

import java.util.ArrayList;

/**
 * Created by 阿炜啊 on 2020/7/12.
 */

public abstract class BasePresenter <V extends BaseView>  {

    public V mView;

    private ArrayList<BaseModel> mModels=new ArrayList<>();

    public BasePresenter(){
        initModel();
    }

    //专门用来初始化M层对象的
    public abstract void initModel();

    public  void bindView(V view) {
        mView = view;
    }

    public void onDestory() {
        if (mModels.size() >0){
            for (int i = 0; i < mModels.size(); i++) {
                BaseModel model = mModels.get(i);
                //拿到每一个m层的对象,通知界面销毁了
                model.onDestroy();
            }
        }
        //2.取消V和P层关联
        mView = null;
    }

    public void addModel(BaseModel model){
        mModels.add(model);
    }
}